package cn.dlc.com.config.advice;

import cn.dlc.com.config.response.ResponseVO;
import cn.dlc.com.config.response.ResponseHttpStatus;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: dlc
 * @Date: 2021/8/2 - 16:40
 * 通用异常处理类
 */
@Slf4j
@RestControllerAdvice
public class CommonExceptionHandler {

    /**
     * 捕获所有的异常
     * @param exception
     * @return
     */
    @ExceptionHandler(value = RuntimeException.class)
    public ResponseVO handler(RuntimeException exception) {

        System.out.println("运行异常");

        // 输出日志
        log.error("运行异常：{},{}",exception.getClass().getName(), exception.getMessage());
        exception.printStackTrace();
        // 响应
        return ResponseVO.error(ResponseHttpStatus.REQUEST_ERROR);
    }
}
